home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / R / RequiredAE XCMD ƒ / source / sendAEPrintDoc.c < prev   
Encoding:
C/C++ Source or Header  |  1991-08-11  |  3.4 KB  |  154 lines  |  [TEXT/KAHL]

  1. /***
  2.  * sendAEPrintDoc.c
  3.  *
  4.  *  This hypercard XFCN will send a AE print document command to some target
  5.  *  application.  The error returned will be returned to the caller.
  6.  *
  7.  *  Gordon Watts July '91 Copyright.
  8.  *
  9.  ***/
  10. #include    <HyperXCmd.h>
  11. #include "hyperUtil.h"
  12.  
  13. /**
  14.  ** some config defines...
  15.  **/
  16.  
  17. #define usageString "sendAEPrintDoc <program>"
  18. #define versionString "sendAEPrintDoc v1.0 Gordon Watts"
  19. #define badString "This should never be returned!  BuG! Bug!"
  20. #define badParamNumString "Wrong number of parameters.  Pass ? to see usage."
  21. #define badMake "Couldn't make the Apple Event!  Bad prog name?"
  22. #define badSend "Couldn't send the AE!"
  23. #define goodDone "\p"
  24. #define badFileList "Couldn't understand your list of files."
  25. #define badAddP "Couldn't add the file list to the apple event!"
  26. #define BugOut(error, string) {Str255 theString; \
  27.         done = true; \
  28.         paramPtr -> returnValue = strToHandle(paramPtr, string); \
  29.         NumToStr (paramPtr, error, theString); \
  30.         theString[theString[0]+1] = 0; \
  31.         SetGlobal (paramPtr, (StringPtr) "\ptheAEXError", \
  32.         (Handle) strToHandle (paramPtr, (char *) &(theString[1])));}
  33.  
  34. /**
  35.  * main 
  36.  *
  37.  *  Main routine for this xfunction.
  38.  *
  39.  **/
  40. pascal void main(XCmdPtr paramPtr)
  41. {
  42.     Boolean done = false;
  43.     TargetID theTarget;
  44.     register int theErr;
  45.     AEAddressDesc targetAddress;
  46.     AppleEvent theAppleEvent, theReplyEvent;
  47.     AEDescList theFileList;
  48.         
  49.  
  50.     /**
  51.      ** Set up default return values
  52.      **/
  53.  
  54.     paramPtr -> returnValue = strToHandle(paramPtr, badString);
  55.     paramPtr -> passFlag = false;
  56.     
  57.     /**
  58.      ** First, do the usage messages: a "!" and a "?".
  59.      **/
  60.     
  61.     if (paramPtr -> paramCount == 1) {
  62.     
  63.         switch (**(paramPtr -> params[0])) {
  64.         
  65.             case '!':
  66.                 BugOut (0, versionString);
  67.                 break;
  68.             
  69.             case '?':
  70.                 BugOut (0, usageString);
  71.                 break;
  72.             
  73.         }
  74.     }
  75.  
  76.     /**
  77.      ** Ok.  Next job, we had better make sure that we have the
  78.      ** correct number of parameters.  Since we need only the 
  79.      ** destination application, it had better be just one!
  80.      **/
  81.     
  82.     if ((!done) && (paramPtr -> paramCount != 2)) {
  83.         BugOut (0, badParamNumString);
  84.     }
  85.  
  86.     /**
  87.      ** Next job is to create the apple event with by using our little
  88.      ** home-made subprogram...
  89.      **/
  90.     
  91.     if (!done) {
  92.         Str255 theProgramName;
  93.         
  94.         ZeroToPas (paramPtr, (char *) (*(paramPtr->params[0])), theProgramName);
  95.         
  96.         theErr = AEFromHCProgram (theProgramName, kCoreEventClass,
  97.                 kAEPrintDocuments, kAutoGenerateReturnID,
  98.                 kAnyTransactionID, &theAppleEvent);
  99.         
  100.         if (theErr != noErr) {
  101.             BugOut (theErr, badMake);
  102.         }
  103.     }
  104.  
  105.     /**
  106.      ** Right-o.  Next job is to try and parse the descriptor...
  107.      ** Use a little subroutine to construct the list
  108.      **/
  109.     
  110.     if (!done) {
  111.  
  112.         theErr = makeFileListFmHCF (paramPtr,
  113.                 (char *) *(paramPtr->params[1]),
  114.                 &theFileList);
  115.         if (theErr != noErr)
  116.             BugOut (theErr, badFileList);
  117.  
  118.     }
  119.  
  120.     /**
  121.      ** Next, add it to the apple event as the single parameter...
  122.      **/
  123.     
  124.     if (!done) {
  125.  
  126.         theErr = AEPutParamDesc (&theAppleEvent, keyDirectObject,
  127.                 &theFileList);
  128.         
  129.         if (theErr != noErr)
  130.             BugOut (theErr, badAddP);
  131.     }
  132.  
  133.     /**
  134.      ** Finally, here we send the apple event...
  135.      **/
  136.     
  137.     if (!done) {
  138.         theErr = AESend (&theAppleEvent, &theReplyEvent,
  139.             kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer,
  140.             kAENormalPriority, kAEDefaultTimeout, 0L, 0L);
  141.         if (theErr != noErr) {
  142.             BugOut (theErr, badSend);
  143.         }
  144.     }
  145.     
  146.     /**
  147.      ** If not done... We are finished...
  148.      **/
  149.     
  150.     if (!done) {
  151.         BugOut (0, goodDone);
  152.     }
  153. }
  154.